package com.didispace.dao;

import com.didispace.domain.Ebook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EBookMapper {

    @Insert("insert into `tbl_ebook`(`name`, `price`) values(#{name}, #{price})")
    int insert(Ebook ebook);

    @Delete("delete from `tbl_ebook` where `id`=#{id}")
    int delete(@Param("id") Long id);

    @Update("update `tbl_ebook` set `name`=#{book.name}, `price`=#{book.price} where `id`=#{id}")
    int update(@Param("id") Long id, @Param("book") Ebook ebook);

    @Select("select `id`, `name`,`status`,`delete`, `price`, `create_time`, `update_time` from `tbl_ebook` where `id`=#{id}")
    Ebook findById(@Param("id") Long id);

    @Select("select `id`, `name`,`status`,`delete`, `price`, `create_time`, `update_time` from `tbl_ebook` where `name` =#{name}")
    Ebook findByName(@Param("name") String name);

    @Select("select `id`, `name`,`status`,`delete`, `price`, `create_time`, `update_time` from `tbl_ebook` where `name` like concat_ws(concat_ws('%', #{name}), '%')")
    List<Ebook> findByNameLike(@Param("name") String name);

    @Select("select `id`, `name`,`status`,`delete`, `price`, `create_time`, `update_time` from `tbl_ebook`")
    List<Ebook> findAll();
}
